<?php
require_once (APPLICATION_DIR."/application/model/Faq.php");

class Faq extends DataObjects_Faq
{
    function getAllFaqInfo()
    {
        $this->selectAdd();
        $this->selectAdd("*");
        $this->find();
        return $this;
    }
    
    function getAllShowFaqInfo()
    {
        $this->selectAdd();
        $this->selectAdd("*");
        $this->whereAdd();
        $this->whereAdd("faq_publish = 1");
        $this->orderBy("faq_order");
        $this->find();
        return $this;
    }
    
    function getListShowFaqInfo()
    {
        $this->selectAdd();
        $this->selectAdd("*");
        $this->whereAdd();
        $this->whereAdd("faq_publish = 1");
        $this->orderBy("faq_order");
        $this->find();
        $result = $this->fetchList();
        return $result;
    }
    
    function tooglePublish($faq_id,$publish)
	{
	    $this->faq_id = $faq_id;
	    $this->faq_publish = 1 - $publish;
	    $this->update();
	}
	
	function getFaqInfoByID($faq_id)
	{
	    $this->selectAdd();
        $this->selectAdd("*");
        $this->whereAdd();
        $this->whereAdd("faq_id = $faq_id");
        $this->find();
        return $this;
	}
	
	function updateFaq($args)
	{
	    $this->faq_id      = $args['faq_id'];
	    $this->faq_order   = $args['faq_order'];
	    $this->faq_question= $args['faq_question'];
	    $this->faq_answer  = $args['faq_answer'];
	    $this->update();
	}
	
	function addFaq($args)
	{
	    $this->faq_order   = $args['faq_order'];
	    $this->faq_question= $args['faq_question'];
	    $this->faq_answer  = $args['faq_answer'];
	    $this->insert();
	}
	
	function deleteFaq($faq_id)
	{
	    $this->faq_id = $faq_id;
	    $this->delete();
	}
	
	function copyQuestionToFaq($question_id)
	{
	    $question      = new Question();
	    $questionInfo  = $question->getQuestionInfoByID($question_id);
	    $questionInfo->fetch();
	    $this->faq_question    = $questionInfo->question_detail;
	    $this->faq_answer      = $questionInfo->question_answer;
	    $this->insert();
	}
}
?>